
public class CosineCompare {
	/* 余弦相似度算法 */
	public static void main(String[] args) throws Exception {
		double[] curve_1 = { 1, 4, 5, 7, 8, 9, 6, 5, 3, 2, 1 }; // 坐标
		double[] curve_2 = { 1, 1.2, 8, 20, 9, 8, 6, 5, 3, 2, 1 }; // 坐标
		double x = 0, y = 0, z = 0;
		for (int i = 0; i < curve_1.length; i++) {
			x += curve_1[i] * curve_1[i];
			y += curve_2[i] * curve_2[i];
			z += curve_1[i] * curve_2[i];
		}
		x = Math.sqrt(x);
		y = Math.sqrt(y);
		System.out.println(z / (x * y));
	}
}
